// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <iostream>
using namespace std;

// ****************************************************************************
//  File:  genvoxcases.cpp
//
//  Purpose:
//    Generates the 48 transforms of a voxel.
//    Points are 0-7, edges are A-L.
//
//  Programmer:  Jeremy Meredith
//  Creation:    June 24, 2004
//
// ****************************************************************************


int voxVerticesFromEdges[12][2] =
{
    { 0, 1 },   /* Edge 0 */
    { 1, 3 },   /* Edge 1 */
    { 2, 3 },   /* Edge 2 */
    { 0, 2 },   /* Edge 3 */
    { 4, 5 },   /* Edge 4 */
    { 5, 7 },   /* Edge 5 */
    { 6, 7 },   /* Edge 6 */
    { 4, 6 },   /* Edge 7 */
    { 0, 4 },   /* Edge 8 */
    { 1, 5 },   /* Edge 9 */
    { 2, 6 },   /* Edge 10 */
    { 3, 7 }    /* Edge 11 */
};


void
SetNode(int node[2][2][2], int id,
        int ox, int oy, int oz, int dx[3], int dy[3], int dz[3],
        int mx, int my, int mz)
{
    ox += dx[0]*mx + dy[0]*my + dz[0]*mz;
    oy += dx[1]*mx + dy[1]*my + dz[1]*mz;
    oz += dx[2]*mx + dy[2]*my + dz[2]*mz;
    node[ox][oy][oz] = id;
}

void
GenCases(int ox, int oy, int oz, int dx[3], int dy[3], int dz[3])
{
    int node[2][2][2];

    SetNode(node, 0, ox, oy, oz, dx,dy,dz, 0, 0, 0);
    SetNode(node, 1, ox, oy, oz, dx,dy,dz, 1, 0, 0);
    SetNode(node, 2, ox, oy, oz, dx,dy,dz, 0, 0, 1);
    SetNode(node, 3, ox, oy, oz, dx,dy,dz, 1, 0, 1);

    SetNode(node, 4, ox, oy, oz, dx,dy,dz, 0, 1, 0);
    SetNode(node, 5, ox, oy, oz, dx,dy,dz, 1, 1, 0);
    SetNode(node, 6, ox, oy, oz, dx,dy,dz, 0, 1, 1);
    SetNode(node, 7, ox, oy, oz, dx,dy,dz, 1, 1, 1);

    int allnodes[8] = {
        node[0][0][0],
        node[1][0][0],
        node[0][0][1],
        node[1][0][1],
        node[0][1][0],
        node[1][1][0],
        node[0][1][1],
        node[1][1][1]
    };
    cerr << "{{";
    cerr << allnodes[0] << ",";
    cerr << allnodes[1] << ",";
    cerr << allnodes[2] << ",";
    cerr << allnodes[3] << ",";
    cerr << allnodes[4] << ",";
    cerr << allnodes[5] << ",";
    cerr << allnodes[6] << ",";
    cerr << allnodes[7] << "},{";
    for (int i=0; i<12; i++)
    {
        int e0 = voxVerticesFromEdges[i][0];
        int e1 = voxVerticesFromEdges[i][1];

        int n0 = allnodes[e0];
        int n1 = allnodes[e1];

        for (int j=0; j<12; j++)
        {
            int j0 = voxVerticesFromEdges[j][0];
            int j1 = voxVerticesFromEdges[j][1];

            if (n0==j0 && n1==j1)
            {
                cerr << "'" << char(int('a')+j) << "'";
            }
            else if (n0==j1 && n1==j0)
            {
                cerr << "'" << char(int('a')+j) << "'";
            }

        }
        if (i<11) cerr << ",";
    }
    cerr << "},";

    int test_dy[3] = 
    {
        dx[1]*dz[2] - dx[2]*dz[1],
        dx[2]*dz[0] - dx[0]*dz[2],
        dx[0]*dz[1] - dx[1]*dz[0]
    };

    bool flip;
    if (test_dy[0]==dy[0] &&
        test_dy[1]==dy[1] &&
        test_dy[2]==dy[2])
    {
        flip = true;
    }
    else 
    {
        flip = false;
    }

    cerr << (flip ? "true " : "false");
    cerr << " }," << endl;
}

int main()
{
    for (int ox=0; ox<=1; ox++)
    {
      for (int oy=0; oy<=1; oy++)
      {
        for (int oz=0; oz<=1; oz++)
        {
            int xaxis[] = {ox==0 ? 1 : -1, 0, 0};
            int yaxis[] = {0, oy==0 ? 1 : -1, 0};
            int zaxis[] = {0, 0, oz==0 ? 1 : -1};

            GenCases(ox,oy,oz, xaxis, yaxis, zaxis);
            GenCases(ox,oy,oz, xaxis, zaxis, yaxis);
            GenCases(ox,oy,oz, yaxis, xaxis, zaxis);
            GenCases(ox,oy,oz, yaxis, zaxis, xaxis);
            GenCases(ox,oy,oz, zaxis, xaxis, yaxis);
            GenCases(ox,oy,oz, zaxis, yaxis, xaxis);
        }
      }
    }
}
